package cate.common.table.res.holy_pet.closeness;

import cate.common.table.ESheet;
import easy.java.dev.note.NoteField;

import java.util.HashMap;
import java.util.Map;

/**
 * 灵宠-亲密等级 Sheet
 *
 * @author ShenSL
 * @since 2023/8/24 14:49
 */
public class HolyPetClosenessSheet extends ESheet<HolyPetClosenessRow> {
    @Override
    public String getSheetName() {
        return "亲密等级";
    }

    @NoteField("灵宠ID->最大等级")
    public Map<Integer, Integer> maxLevels = new HashMap<>();

    @Override
    public void decode() {
        super.decode();
        getList().forEach(row -> {
            if (!maxLevels.containsKey(row.petId)) {
                maxLevels.put(row.petId, row.level);
            } else if (row.level > maxLevels.get(row.petId)) {
                maxLevels.put(row.petId, row.level);
            }
        });
    }

    /**
     * 获取灵宠最大亲密等级
     */
    public int getMaxLevel(int id) {
        return maxLevels.getOrDefault(id, 0);
    }

    /**
     * 获取配置项
     *
     * @param id    灵宠ID
     * @param level 亲密等级
     */
    public HolyPetClosenessRow getRow(int id, int level) {
        return getList().stream().filter(row -> row.petId == id && row.level == level)
                .findAny().orElse(null);
    }
}
